home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
a_utils
/
expanded.lha
/
test_suite
/
testmap.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-19
|
18KB
|
690 lines
//
// Linear-Affine-Projective Geometry Package
//
// testmap.C
//
// $Header$
//
// William J.R. Longabaugh
// University of Washington
//
// Test programs for the linear-affine-projective geometry
// package described in William J.R. Longabaugh, "An Expanded
// System for Coordinate-Free Geometric Programming", Master's
// thesis, University of Washington, 1992.
//
// Copyright (c) 1992, William J.R. Longabaugh
// Copying, use and development for non-commercial purposes permitted.
// All rights for commercial use reserved.
// This software is unsupported and without warranty; it is
// provided "as is".
//
// ***********************************************************************
#include "Lap.h"
#include <math.h>
extern void test1(void);
extern void test2(void);
extern void test3(void);
extern void test4(void);
extern void test5(void);
extern void test6(void);
extern void test7(void);
extern void test8(void);
extern void test9(void);
extern void test10(void);
// ***********************************************************************
int main(void)
{
test1();
test2();
test3();
test4();
test5();
test6();
test7();
test8();
test9();
test10();
return (0);
}
// ***********************************************************************
// Test the casting of multimaps and geobs to maps:
void test1(void)
{
cout << "ENTERING TEST1\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", v, a);
// Create a first order map and convert it to a Multimap. Use this
// multimap to convert back to a map:
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
APoint a2(fra, ScalarList(2.2, 5.1, 1.0));
APoint a3(fra, ScalarList(-6.7, 2.3, 1.0));
Simplex s1("test simplex", a, GeObList(a1, a2, a3));
Simplex std = a.StdSimplex();
AffineMap am(std, s1);
MAM multi(am);
AffineMap newmap(multi);
GeOb hold = am(std[1]);
cout << hold;
hold = multi(std[1]);
cout << hold;
hold = newmap(std[1]);
cout << hold;
// Fully evaluate the multimap and convert to a map to the reals
// (Domain space will be the dual of the linearization):
MAM noargp;
noargp = multi(GeObList(fra[2]));
LinearMap newmapl = noargp;
Vector lin = a3;
Vector lind = lin.Dual();
Scalar output = newmapl(lind).ToScalar();
cout << "\n result = "<< output << "\n";
// Cast a geob to a map:
PPoint pp1(a1);
newmapl = pp1;
output = newmapl(lind).ToScalar();
cout << "\n result = "<< output << "\n";
}
// ***********************************************************************
// Tests of map application, obtaining associated linear:
void test2(void)
{
cout << "ENTERING TEST2\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", v, a);
// Create an affine map:
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
APoint a2(fra, ScalarList(2.2, 5.1, 1.0));
APoint a3(fra, ScalarList(-6.7, 2.3, 1.0));
APoint a4(fra, ScalarList(-1.4, -7.9, 1.0));
Vector zv(v.StdBasis(), ScalarList(0.0, 0.0, 0.0));
Simplex s1("test simplex", a, GeObList(a1, a2, a3));
Simplex std = a.StdSimplex();
AffineMap am(s1, std);
GeOb ar = am(a2);
cout << ar;
GeOb arv = am(a1 - a3);
cout << arv;
LinearMap almp = am.AssocLinear();
arv = almp(a1 - a2);
cout << arv;
// Affine map to linear subset:
VSubSet targ("target subset", v, GeObList(a1, a2));
AffineMap aml(a.StdSimplex(), targ, GeObList(a1, zv, a2));
VBasis vb = v.StdBasis();
GeOb res = aml(std[2]);
cout << res;
res = aml(std[0] - std[2]);
cout << res;
almp = aml.AssocLinear();
res = almp(std[0] - std[2]);
cout << res;
// Affine map from projective space:
AffineMap apm(p.StdAffineSubset(), GeObList(a1, a2, a3), a.StdSimplex());
// g++ problem again:
// PPoint pp1 = (5.0 * a1.MapTo(VECTOR)).MapTo(VEC_EC).MapTo(PROJ_POINT);
GeOb hold = a1.MapTo(VECTOR);
hold = 5.0 * hold;
hold = hold.MapTo(VEC_EC);
GeOb pp1 = hold.MapTo(PROJ_POINT);
ar = apm(pp1);
cout << ar;
}
// ***********************************************************************
// Tests inverting, transpose:
void test3(void)
{
cout << "ENTERING TEST3\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", v, a);
// Create an affine map, invert it:
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
APoint a2(fra, ScalarList(2.2, 5.1, 1.0));
APoint a3(fra, ScalarList(-6.7, 2.3, 1.0));
APoint a4(fra, ScalarList(-1.4, -7.9, 1.0));
Simplex s1("test simplex", a, GeObList(a1, a2, a3));
Simplex std = a.StdSimplex();
AffineMap am(std, s1);
GeOb apt = am(std[1]);
cout << apt;
am = am.Inv();
apt = am(apt);
cout << apt;
// Create a linear map, take the transpose:
Basis bas = v.StdBasis();
Vector v1(bas, ScalarList(3.6, -4.5, 2.4));
Vector v2(bas, ScalarList(2.2, 5.1, -3.2));
Vector v3(bas, ScalarList(-6.7, 2.3, 1.0));
Vector v4(bas, ScalarList(-1.4, -7.9, 8.2));
VBasis b1("test basis", v, GeObList(v1, v2, v3));
LinearMap lm(b1, bas);
Vector v2d = v2.Dual();
Scalar output = v2d.Apply(v4);
cout << "\n result = "<< output << "\n";
Vector res = lm(v4);
lm = lm.Trans().Inv();
Vector resd = lm(v2d);
output = resd.Apply(res);
cout << "\n result = "<< output << "\n";
}
// ***********************************************************************
// Induced maps:
void test4(void)
{
cout << "ENTERING TEST4\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
ASpace as2("Test affine space 2", 2, TRUE);
PSpace p("Test projective space", v, a);
// Build an affine map:
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
APoint a3(fra, ScalarList(-3.4, 2.8, 1.0));
Simplex s1("test simplex", a, GeObList(a1, a2, a3));
AffineMap am(s1, as2.StdSimplex());
GeOb resa = am(a2);
cout << resa;
PPoint pp2 = a2;
Vector v2 = a2;
ProjectiveMap ip = am.InducedProjective();
LinearMap il = am.InducedLinear();
GeOb res = il(v2);
cout << res;
GeOb resp = ip(pp2);
cout << resp;
}
// ***********************************************************************
// Composition:
void test5(void)
{
cout << "ENTERING TEST5\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
ASpace as2("Test affine space 2", 2, TRUE);
PSpace p("Test projective space", v, a);
// Build affine maps:
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
APoint a3(fra, ScalarList(-3.4, 2.8, 1.0));
Simplex as2std = as2.StdSimplex();
Simplex s1("test simplex", a, GeObList(a1, a2, a3));
AffineMap am(as2std, s1);
Simplex s2("test simplex2", a, GeObList(a3, a1, a2));
AffineMap am2(s2, as2std);
// Build a projective map:
HFrame hfra = p.StdBasis();
PPoint p1(hfra, ScalarList(2.1, 3.6, -4.5));
PPoint p2(hfra, ScalarList(2.5, 7.8, 6.2));
PPoint p3(hfra, ScalarList(-3.4, 2.8, 4.4));
PPoint p4(hfra, ScalarList(-8.8, 3.9, -2.2));
HFrame hf1("test hframe", p, GeObList(p1, p2, p3, p4));
ProjectiveMap pm(p.StdBasis(), hf1);
// Compose:
AffineMap amc = am2.Compose(am);
GeOb resa = am2(am(as2std[2]));
cout << resa;
resa = amc(as2std[2]);
cout << resa;
ProjectiveMap pmc = pm.ComposeProj(am);
GeOb resp = pm(am(as2std[2]));
cout << resp;
resa = pmc(as2std[2]);
cout << resp;
}
// ***********************************************************************
// Affine functionals:
void test6(void)
{
cout << "ENTERING TEST6\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", v, a);
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
APoint a3(fra, ScalarList(-3.4, 2.8, 1.0));
Simplex s1("test simplex", a, GeObList(a1, a2, a3));
AffineMap am(s1, Reals.FullSet(), GeObList(3.4, 1.2, 5.6));
Scalar output = am(a2).ToScalar();
cout << "\n result = "<< output << "\n";
output = am(a3).ToScalar();
cout << "\n result = "<< output << "\n";
output = am(a2 - a3).ToScalar();
cout << "\n result = "<< output << "\n";
Vector adv = am.AssocDualVector();
output = adv.Apply(a2 - a3);
cout << "\n result = "<< output << "\n";
}
// ***********************************************************************
// Tests of various linear map constructors:
void test7(void)
{
cout << "ENTERING TEST7\n";
VSpace v("Test vector space", 3, TRUE);
VSpace vs2("Test vector space 2", 4, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", v, a);
// Build bases, linear subsets:
VBasis bas = v.StdBasis();
APoint a1(a.StdBasis(), ScalarList(3.6, -4.5, 1.0));
Vector v1 = a1;
Vector v2(bas, ScalarList(2.5, 7.8, -2.4));
Vector v3(bas, ScalarList(-3.4, 2.8, 5.6));
VBasis b1("test basis", v, GeObList(v1, v2, v3));
Vector v4(bas, ScalarList(3.1, -6.5, 9.8));
Vector v5(bas, ScalarList(1.2, -3.4, -5.8));
Vector v6(bas, ScalarList(4.6, -6.4, 5.6));
VBasis b2("test basis 2", v, GeObList(v4, v5, v6));
VBasis bas2 = vs2.StdBasis();
Vector v7(bas2, ScalarList(2.2, 6.7, 3.1, 9.9));
Vector v8(bas2, ScalarList(-1.2, 2.7, 7.8, 5.6));
Vector v9(bas2, ScalarList(0.9, 4.6, 1.4, 5.1));
Vector v10(bas2, ScalarList(6.8, -2.9, 5.2, 5.6));
VBasis b3("test basis 3", vs2, GeObList(v7, v8, v9, v10));
VSubSet sub1("subset 1", v, GeObList(v1, v3));
VSubSet sub2("subset 2", v, GeObList(v2, v3));
VSubSet sub3("subset 3", vs2, GeObList(v7, v8));
VSubSet sub4("subset 4", vs2, GeObList(v9, v7, v8));
LinearMap lm1(b1, b2);
GeOb vout = lm1(v2);
cout << vout;
vout = lm1(v2 + v3);
cout << vout;
LinearMap lm2(b1, sub4, GeObList(v9, v7, v8));
vout = lm2(v2);
cout << vout;
vout = lm2(v2 + v3);
cout << vout;
LinearMap lm3(b1, sub4, GeObList(v9, v7, v9));
vout = lm3(v2);
cout << vout;
vout = lm3(v2 + v3);
cout << vout;
LinearMap lm4(sub4, GeObList(v8, v9, v7), b2);
vout = lm4(v8);
cout << vout;
vout = lm4(v8 + v7);
cout << vout;
LinearMap lm5(sub3, GeObList(v8 + v7, v7), sub1, GeObList(a1, v1 + v3));
vout = lm5(v7);
cout << vout;
vout = lm5(v8 + v7);
cout << vout;
}
// ***********************************************************************
// Tests of various affine map constructors:
void test8(void)
{
cout << "ENTERING TEST8\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
ASpace as2("Test affine space 2", 3, TRUE);
PSpace p("Test projective space", v, a);
// Build simplices, affine subsets:
Simplex smp = a.StdSimplex();
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
Vector v1 = a1;
APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
APoint a3(fra, ScalarList(-3.4, 2.8, 1.0));
Simplex s1("test simplex", a, GeObList(a1, a2, a3));
APoint a4(fra, ScalarList(3.1, -6.5, 1.0));
APoint a5(fra, ScalarList(1.2, -3.4, 1.0));
APoint a6(fra, ScalarList(4.6, 6.4, 1.0));
Simplex s2("test simplex 2", a, GeObList(a4, a5, a6));
Frame fra2 = as2.StdBasis();
APoint a7(fra2, ScalarList(2.2, 6.7, 9.9, 1.0));
APoint a8(fra2, ScalarList(-1.2, 7.8, 5.6, 1.0));
APoint a9(fra2, ScalarList(4.6, 1.4, 5.1, 1.0));
APoint a10(fra2, ScalarList(6.8, -2.9, 5.6, 1.0));
Simplex s3("test simplex 3", as2, GeObList(a7, a8, a9, a10));
VBasis bas = v.StdBasis();
Vector v2(bas, ScalarList(2.5, 7.8, -2.4));
Vector v3(bas, ScalarList(2.9, -3.4, 5.6));
VSubSet vsub1("vec subset 1", v, GeObList(v2, v3));
ASubSet sub1("subset 1", a, GeObList(a1, a3));
ASubSet sub2("subset 2", a, GeObList(a2, a3));
ASubSet sub3("subset 3", as2, GeObList(a7, a8));
ASubSet sub4("subset 4", as2, GeObList(a9, a7, a8));
ASubSet sub5("subset 5", v, GeObList(a2, a3));
ASubSet sub6("subset 6", p, a2, GeObList(AVectorEC(a2 - a3)));
AffineMap am1(s1, s2);
GeOb aout = am1(a2);
cout << aout;
aout = am1((a2 + a3) / 2);
cout << aout;
AffineMap am2(s1, sub4, GeObList(a9, a7, a8));
aout = am2(a2);
cout << aout;
aout = am2((a2 + a3) / 2);
cout << aout;
AffineMap am3(s1, sub4, GeObList(a9, a7, a9));
aout = am3(a2);
cout << aout;
aout = am3((a2 + a3) / 2);
cout << aout;
AffineMap am4(s1, vsub1, GeObList(v2, v3, v2 + (3.0 * v3)));
aout = am4(a2);
cout << aout;
aout = am4((a2 + a3) / 2);
cout << aout;
AffineMap am5(sub4, GeObList(a8, a9, a7), s2);
aout = am5(a9);
cout << aout;
aout = am5((a7 + a8) / 2);
cout << aout;
AffineMap am6(sub1, GeObList(a1, a3), sub5, GeObList(a2, (a2+a3)/ 2.0));
aout = am6(a1);
cout << aout;
aout = am6((a1 + a3) / 2);
cout << aout;
AffineMap am7(sub6, GeObList((a2 + a3)/2.0, a2), sub5, GeObList(a2, a3));
aout = am7(a2);
cout << aout;
aout = am7((a2 + a3) / 2);
cout << aout;
AffineMap am8(sub6, GeObList(a2, a3), sub1, GeObList(v1, a3));
aout = am8(a2);
cout << aout;
aout = am8((a2 + a3) / 2);
cout << aout;
}
// ***********************************************************************
// Tests of various projective map constructors:
void test9(void)
{
cout << "ENTERING TEST9\n";
VSpace v("Test vector space", 4, TRUE);
ASpace a("Test affine space", 3, TRUE);
PSpace p("Test projective space", v, a);
PSpace ps2("Test proj space 2", 2);
VSpace t = a.GetSpace(TANGENT);
// Build bases, projective subsets:
HFrame hfra = p.StdBasis();
PPoint p1(hfra, ScalarList(2.2, 6.7, 3.1, 9.9));
PPoint p2(hfra, ScalarList(-1.2, 2.7, 7.8, 5.6));
PPoint p3(hfra, ScalarList(0.9, 4.6, 1.4, 5.1));
PPoint unit123(hfra, ScalarList(1.9, 14.0, 12.3, 20.6));
PPoint p4(hfra, ScalarList(6.8, -2.9, 5.2, 5.6));
PPoint unit234(hfra, ScalarList(6.5, 4.4, 14.4, 16.3));
PPoint p5(hfra, ScalarList(7.8, 3.2, -5.6, 9.3));
HFrame f1("test hframe 1", p, GeObList(p1, p2, p3, p4) + GeObList(p5));
ProjectiveMap pm1(f1, hfra);
GeOb pout = pm1(p2);
cout << pout;
pout = pm1(p5);
cout << pout;
PSubSet ps("regular 2d psubset", p, GeObList(p1, p2, p3));
PSubSet psr("removed psubset", p, GeObList(p1), GeObList(p2, p3, p4));
VBasis bas = v.StdBasis();
Vector v1(bas, ScalarList(-2.5, 3.9, -9.7, 8.7));
Vector v2(bas, ScalarList(2.5, 7.8, -2.4, 1.6));
Vector v3(bas, ScalarList(-3.4, 2.8, 5.6, 7.4));
Vector v4(bas, ScalarList(3.1, -6.5, 9.8, -6.5));
Vector v5(bas, ScalarList(1.2, -3.4, -5.8, 2.8));
PSubSet psl("psubset in v", v, GeObList(v1, v2, v3));
PSubSet pslf("full psubset in v", v, GeObList(v1, v2, v3, v4));
VBasis bast= t.StdBasis();
AVector vt1(bast, ScalarList(-2.5, 3.9, 8.7));
AVector vt2(bast, ScalarList(2.5, -2.4, 1.6));
AVector vt3(bast, ScalarList(-3.4, 2.8, 5.6));
AVector vt4(bast, ScalarList(-6.5, 9.8, -6.5));
AVector vt5(bast, ScalarList(1.2, -5.8, 2.8));
PSubSet pst("psubset in t", t, GeObList(vt1, vt2, vt3));
// to vector space:
ProjectiveMap pm2(f1, pslf, GeObList(v1, v2, v3, v4) + GeObList(v5));
pout = pm2(p2);
cout << pout;
pout = pm2(p5);
cout << pout;
// non-invert:
ProjectiveMap pm3(psr, GeObList(p2, p3, p4, unit234), ps2.StdBasis());
pout = pm3(p2);
cout << pout;
pout = pm3(p4);
cout << pout;
ProjectiveMap pm4(ps, GeObList(p1, p2, p3, unit123), ps2.StdBasis());
pout = pm4(p2);
cout << pout;
pout = pm4(unit123);
cout << pout;
// non-invert:
ProjectiveMap pm5(psr, GeObList(p2, p3, p4, unit234),
ps, GeObList(p1, p2, p3, unit123));
pout = pm5(p2);
cout << pout;
pout = pm5(unit234);
cout << pout;
// to tangent space:
ProjectiveMap pm6(ps, GeObList(p1, p2, p3, unit123),
pst, GeObList(vt1, vt2, vt3, vt1 + vt2 + vt3));
pout = pm6(p2);
cout << pout;
pout = pm6(unit123);
cout << pout;
}
// ***********************************************************************
// Composition with affine subsets of different dimensions in a
// projective space:
void test10(void)
{
cout << "ENTERING TEST10\n";
VSpace v("Test vector space", 4, TRUE);
ASpace a("Test affine space", 3, TRUE);
PSpace p("Test projective space", v, a);
VSpace t = a.GetSpace(TANGENT);
Frame fra = a.StdBasis();
VBasis vbas = v.StdBasis();
HFrame hfr = p.StdBasis();
VBasis tbas = t.StdBasis();
Vector v1(vbas, ScalarList(6.7, 3.4, 2.8, 1.2));
Vector v2(vbas, ScalarList(2.5, 5.7, 1.3, 9.5));
Vector v3(vbas, ScalarList(7.9, 3.5, 4.1, 2.7));
Vector v4(vbas, ScalarList(7.3, 4.6, 2.2, 9.3));
APoint p1(fra, ScalarList(6.7, 3.4, 2.8, 1.0));
APoint p2(fra, ScalarList(3.6, 2.5, -2.1, 1.0));
APoint p3(fra, ScalarList(2.2, 1.9, -0.3, 1.0));
APoint p4(fra, ScalarList(2.5, 1.6, 7.4, 1.0));
PPoint pp1(hfr, ScalarList(6.7, 3.4, 2.8, 3.4));
PPoint pp2(hfr, ScalarList(3.6, 2.5, -2.1, 3.1));
PPoint pp3(hfr, ScalarList(2.2, 1.9, -0.3, 5.1));
PPoint pp4(hfr, ScalarList(7.4, 1.0, 2.5, 1.6));
ASubSet as1dp("as1dp", p, pp1, GeObList(pp2));
ASubSet as2dp("as2dp", p, pp1, GeObList(pp2, pp3));
ASubSet as3dp("as3dp", p, pp1, GeObList(pp2, pp3, pp4));
ASpace ad1("ad1", 1, TRUE);
ASpace ad2("ad2", 2, TRUE);
ASpace ad3("ad3", 3, TRUE);
AffineMap amap(ad1.StdSimplex(), as1dp,
GeObList((2.3 * pp2 - 1.3 * pp1), (.7 * pp2 + .3 * pp1)));
AffineMap amap2(as3dp,
GeObList((0.7 * pp1 - 0.8 * pp2 + 0.5 * pp3 + 0.6 * pp4),
(1.4 * pp1 - 0.3 * pp2 - 1.6 * pp3 + 1.5 * pp4),
(0.3 * pp1 + 0.3 * pp2 + 0.3 * pp3 + 0.1 * pp4),
(0.4 * pp1 + 0.7 * pp2 + 0.8 * pp3 - 0.9 * pp4)),
ad3.StdSimplex());
AffineMap acomp = amap2.Compose(amap);
if (acomp.Invertible()) {
cout << "Failed\n";
} else {
cout << "OK\n";
}
Simplex ad1simp = ad1.StdSimplex();
APoint test;
APoint testin = ad1simp[1];
test = amap(testin);
test = amap2(test);
cout << test;
test = acomp(testin);
cout << test;
testin = ad1simp[0];
test = amap(testin);
test = amap2(test);
cout << test;
test = acomp(testin);
cout << test;
testin = -0.6 * ad1simp[1] + 1.6 * ad1simp[0];
test = amap(testin);
test = amap2(test);
cout << test;
test = acomp(testin);
cout << test;
}
// ***********************************************************************